<?php
class About extends Doctrine_Record {
    public function setTableDefinition() {
        $this->setTableName('about');
        $this->hasColumn('me', 'string', 10000);
    }
    
    public function setUp(){
        $this->hasMany('Client as clients', array(
            'local' => 'id',
            'foreign' => 'id_about'
        ));
        $this->hasMany('Imagen as imagenes', array(
            'local' => 'id',
            'foreign' => 'id_about'
        ));
    }    
    
    //GETTERS Y SETTERS
    public static function getInstance () {
        return Doctrine::getTable('about')->find(1);
    }
    public function getMe () {
        return utf8_decode($this->_get('me'));
    }
    public function setMe ($q) {
        $this->_set('me', utf8_encode($q));
    }
    
    public function clientsToString () {
        $txt = '';
        foreach ($this->clients as $client) {
            $txt .= $client->value.'|';
        }
        return substr($txt, 0, -1);
    }
    
    public function imagenes () {
        $q = Doctrine_Query::create()
            ->select('i.*')
            ->from('Imagen i')
            ->innerJoin('i.about a')
            ->where('a.id = '.$this->id)
            ->orderBy('i.orden');
        return $q->execute();
    }
    //FIN GETTERS Y SETTERS
}
?>